package com.yhxd.modular.news.entity;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 信息分类
 */
@Data
@Entity(name = "news_classify")
@EntityListeners(value = AuditingEntityListener.class)
public class Classify implements Serializable {

    @ApiModelProperty(value = "id")
    @Id
    @GeneratedValue(generator = "idGenerator")
    @GenericGenerator(name = "idGenerator", strategy = "com.yhxd.utils.IdUtils")
    @Column(name = "id")
    private Long id;

    @ApiModelProperty(value = "分类名称")
    @Column(name = "cla_name")
    private String claName;

    @ApiModelProperty(value = "分类类型，0信息类型，1信息小类")
    @Column(name = "cla_type")
    private Integer claType;

    @ApiModelProperty(value = "父类型id")
    @Column(name = "pid")
    private Long pid;

    @ApiModelProperty(value = "父类型名称")
    @Column(name = "pname")
    private String pname;

    @ApiModelProperty(value = "创建人")
    @Column(name = "create_name")
    private String createName;

    @ApiModelProperty(value = "创建时间")
    @Temporal(TemporalType.TIMESTAMP)
    @CreatedDate
    @Column(name = "create_time")
    private Date createTime;

    @ApiModelProperty(value = "修改人")
    @Column(name = "update_name")
    private String updateName;

    @ApiModelProperty(value = "修改时间")
    @Temporal(TemporalType.TIMESTAMP)
    @LastModifiedDate
    @Column(name = "update_time")
    private Date updateTime;

    @ApiModelProperty(value = "数据是否可用，0不可用，1可用")
    @Column(name = "enable")
    private Integer enable = 1;

    @ApiModelProperty(value = "排序")
    @Column(name = "sort")
    private Integer sort;

    @ApiModelProperty(value = "前端是否显示，0不显示，1显示")
    @Column(name = "is_show")
    private Integer isShow = 1;

    @ApiModelProperty(value = "版本号")
    @Column(name = "version")
    private Integer version;

    @ApiModelProperty(value = "链接地址")
    @Column(name = "link_url")
    private String linkUrl;

    /*
       第1种：大类、小类、详情。中心简介
       第2种：大类、小类、列表、详细。部门简报、
       第3种：大类、列表。资料下载、友情链接
       第4钟：大类、列表、详情。工作简报、中心动态、通知公告、深圳不动产*/

    @ApiModelProperty(value = "类型")
    @Column(name = "type")
    private Integer type;

    @ApiModelProperty(value = "附件集合")
    @OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "pid")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<Classify> classifys;

    public Classify(){}
    public Classify(Long id) {
        this.id = id;
    }
    public Classify(Long id,Long pid) {
        this.id = id;
        this.pid = pid;
    }
}
